Options that Control C++ Dialect

Contents|Index|Previous|Next
Options that control C++ dialect

The following documentation describes the command-line options that are only meaningful for C++ programs; but you can also use most of the GNU compiler options regardless of what language your program uses. For instance, you might compile a file, firstClass.C, like the following example.

    g++  -g  -felide-constructors  -O  -c  firstClass.C

In the previous example, only -felide-constructors is an option meant only for C++ programs; you can use the other options with any language supported by GNU CC. The following lists options that are only for compiling C++ programs.

-fno-access-control

Turn off all access checking. This switch is mainly useful for working around bugs in the access control code.

-fall-virtual

Treat all possible member functions as virtual, implicitly. All member functions (except for constructor functions and new or delete member operators) are treated as virtual functions of the class where they appear.
This does not mean that all calls to these member functions will be made through the internal table of virtual functions. Under some circumstances, the compiler can determine that a call to a given virtual function can be made directly; in these cases the calls are direct in any case.

-fcheck-new

Check that the pointer returned by operator `new` is non-null before attempting to modify the storage allocated. The current ANSI C++Working Paper requires that operatornew never return a null pointer, so this check is normally unnecessary.

-fconserve-space

Put uninitialized or runtime-initialized global variables into the common segment, as C does. This saves space in the executable at the cost of not diagnosing duplicate definitions. If you compile with this flag and your program mysteriously crashes after main() has completed, you may have an object that is being destroyed twice because two definitions were merged.
This option is no longer useful on most targets, now that support has been added for putting variables into BSS without making them common.

-fdollars-in-identifiers

Accept the dollar sign ($) in identifiers. You can also explicitly prohibit use of ‘$’ with the -fno-dollars-in-identifiers option. GNU C++ allows ‘$’ by default on some target systems but not others. Traditional C allowed the character ‘$’, to form part of identifiers. However, ANSI C and C++ forbids ‘$’ in identifiers.

-fembedded-cxx

Incompliance with the Embedded C++ specification, make illegal the use of templates, exception handling, multiple inheritance, or RTTI. Attempts to use namespsaces are also not allowed. This makes the use of some keywords result in warnings by default: template, typename, catch, throw, try, using, namespace, dynamic_cast, static_cast, reinterpret_cast, const_cast, and typeid. To make warnings not be given as errors, add the -pedantic-errors flag.

-fno-elide-constructors

The C++ standard allows an implementation to omit creating a temporary which is only used to initialize another object of the same type. Specifying this option disables that optimization, and forces G++ to call the copy constructor in all cases.

-fexternal-templates

Cause template instantiations to obey #pragma interface and implementation; template instances are emitted or not according to the location of the template definition. See Where’s the template? for more explanation of templates.

-falt-external-templates

Similar to -fexternal-templates, but template instances are emitted or not according to the place where they are first instantiated. See Where’s the template? for more explanation on templates.

-ffor-scope
-fno-for-scope

If -ffor-scope is specified, the scope of variables declared in a for-init-statement is limited to the ‘for’ loop itself, as specified by the draft C++ standard. If -fno-for-scope is specified, the scope of variables declared in a for-init-statement extends to the end of the enclosing scope, as was the case in old versions of gcc, and other (traditional) implementations of C++.

The default if neither flag is given to follow the standard, but to allow and give a warning for old-style code that would otherwise be invalid, or have different behavior.

-fno-gnu-keywords

Do not recognize classof, headof, signature, sigof or typeof as a keyword, so that code can use these words as identifiers. Instead, use the keywords, __classof__, __ headof__, __signature__, __sigof__, and __typeof__. -ansi implies -fno-gnu-keywords.

-fguiding-decls

Treat a function declaration with the same type as a potential function template instantiation as though it declares that instantiation, not a normal function. If a definition is given for the function later in the translation unit (or another translation unit if the target supports weak symbols), that definition will be used; otherwise the template will be instantiated. This behavior reflects the C++ language prior to September 1996, when guiding declarations were removed.
This option implies -fname-mangling-version-0, and will not work with other name mangling versions. Like all options that change the ABI, all C++ code, including `libgcc.a` must be built with the same setting of this option.

-fno-implicit-templates

Never emit code for templates which are instantiated implicitly (i.e., by use); only emit code for explicit instantiations. See Where’s the template? for more explanation on templates.

-fhandle-signatures

Recognize the signature and sigof keywords for specifying abstract types. The default (-fno-handle-signatures) is not to recognize them. See Type abstraction using signatures.

`-fhonor-std`

Treat the namespace `std` as a namespace, instead of ignoring it. For compatibility with earlier versions of G++, the compiler will, by default, ignore `namespace-declarations`, `using-declarations`, `using-directives`, and `namespace-names`, if they involve `std`.

-fhuge-objects

Support virtual function calls for objects that exceed the size representable by a short int call. Users should not use this flag by default; if you need to use it, the compiler will tell you so.
IMPORTANT!
As with all options that change the ABI, all C++ code, including , must be built with the same setting of this option.
This flag is not useful when compiling with -fvtable-thunks.

-finit-priority

Support ‘`__attribute__ ((init_priority (n)))`’ for controlling the order of initialization of file-scope objects. On ELF targets, this requires the GNU linker (version 2.10 or later). `n`
represents a numerical priority from 0 to 65535. Lower is higher priority.

-fno-implement-inlines

To save space, do not emit out-of-line copies of inline functions controlled by ‘#pragma implementation’. This will cause linker errors if these functions are not inlined everywhere they are called.

-fstrict-prototype

Within an ‘extern `“C”`’ linkage specification, treat a function declaration with no arguments, such as `int foo();`, as declaring the function to take no arguments. Normally, such a declaration means that the function foo can take any combinaion of arguments, as in C. `-pedantic` implies `-fstrict-prototype` unless overriden with `-fnostrict-prototype`.

Specifying this option will also suppress implicit declarations of functions.
This flag no longer affects declarations with C++ linkage.

-fname-mangling-version-n

Control the way in which names are mangled. Version 0 is compatible with versions of G++ before 2.8. Version 1 is the default. Version 1 will allow correct mangling of function templates. For example, version 0 mangling does not mangle `foo<int, double>` and `foo<int, char>` given this declaration:

    template <class T, class U> void foo(T t);

-fno-nonnull-objects

Don’t assume that a reference is initialized to refer to a valid object. Although the current C++ Working Paper prohibits null references, some old code may rely on them; you can use -fno-nonnull-objects to turn on checking.
At the moment, the compiler only does this checking for conversions to virtual base classes.

-foperator-names

Recognize the operator name keywords and, bitand, bitor, compl, not, or and xor as synonyms for the symbols they refer to. -ansi implies -foperator-names.

-frepo

Enable automatic template instantiation. This option also implies -fno-implicit-templates. See Where’s the template? for more explanation of templates.

-fno-optional-diags

Disable diagnostics that the standard says a compiler does not need to issue. Currently, this means the diagnostic for a name having multiple meanings within a class.

-fsquangle

-fno-squangle

-fsquangle will enable a compressed form of name mangling for identifiers. In particular, it helps to shorten very long names by recognizing types and class names which occur more than once, replacing them with special short ID codes. This option also requires any C++ libraries being used to be compiled
with this option as well. The compiler has this disabled (the equivalent of -fno-squangle) by default.
IMPORTANT!
As with all options that change the ABI, all C++ code, including , must be built with the same setting of this option.
This flag is not useful when compiling with -fvtable-thunks.

-fthis-is-variable

Permit assignment to ‘this’. The incorporation of user-defined free store management into C++ has made assignment to ‘this’ an anachronism. Therefore, by default it is invalid to assign to this within a class member function; that is, GNU C++ treats ‘this’ in a member function of class ‘X’ as a non-lvalue of type ‘X*’
However, for backwards compatibility, you can make it valid with -fthis-is-variable.

-fvtable-thunks

Use thunks to implement the virtual function dispatch table (vtable). The traditional (cfront-style) approach to implementing vtables was to store a pointer to the function and two offsets for adjusting the ‘this’ pointer at the call site. Newer implementations store a single pointer to a ‘thunk’ function which does any necessary adjustment and then calls the target function.
This option also enables a heuristic for controlling emission of vtables; if a class has any non-inline virtual functions, the vtable will be emitted in the translation unit containing the first one of those.
IMPORTANT!
As with all options that change the ABI, all C++ code, including , must be built with the same setting of this option.
This flag is not useful when compiling with -fvtable-thunks.

-ftemplate-depth-n

Set the maximum instantiation depth for template classes to n. A limit on the template instantiation depth is needed to detect endless recursions during template class instantiation. ANSI/ISO C++ conforming programs must not rely on a maximum depth greater than 17.

-nostdinc++

Do not search for header files in the standard directories specific to C++, but do still search the other standard directories. (This option is used when building the C++ library.)

In addition, the following options for optimization, warning, and code generation have meanings only for C++ programs.

-fno-default-inline

Do not assume inline for functions defined inside a class scope. See Options that control optimization.
Note:
Such class scope defined functions will have linkage like inline functions; they just won’t be inlined by default.

-Wold-style-cast
-Woverloaded-virtual

Warnings that apply only to C++ programs. See Options to request or suppress warnings.

-Weffc++

Warn about violation of some style rules from Effective C++ by Scott Myers.

Top|Contents|Index|Previous|Next